home *** CD-ROM | disk | FTP | other *** search
- /*
- * ToolFrontEndPanel.c - ToolServer Front End Drop-In Preferences
- */
-
- /* standard headers */
- #include <stdarg.h>
- #include <stdio.h>
- #include <string.h>
-
- /* system headers */
- #include <AERegistry.h>
- #include <Resources.h>
- #include <TextUtils.h>
- #include <Controls.h>
- #include <LowMem.h>
- #include <StandardFile.h>
- #include <Sound.h>
-
- /* compiler headers */
- #include <A4Stuff.h>
- #include <SetUpA4.h>
- #include <DropInPanel.h>
-
- /* project headers */
- #include "ToolFrontEnd.h"
- #include "MoreFilesExtras.h"
-
-
- /* current version number for our prefs data */
- #define PTOOLFRONTENDVERSION 2
-
-
- // comment out this line to enable debugging probes
- #define DebugStr(s)
-
-
- enum {
- kItemListIDV1 = 128,
- kItemListID = 130,
- kIncludeScannerItem = 1,
- kIncludePathItem = 2,
- kIncludeBoxItem = 5,
- kCommandLabelItem = 6,
- kCommandItem = 7,
- kExtensionPopupItem = 8,
- kScriptIncludeFileItem = 10,
- kOverallBoxItem = 11,
- kImportSettingsItem = 12,
- kGetExtensionDialog = 129,
- kExtensionTextItem = 4
- };
-
-
- typedef struct
- {
- short current; // current selection in popup menu
- Boolean enableIncludes; // scan for include files
- Boolean popupsInitialized; // has the popup been initialized?
- PanelParameterBlock *pb; // the parameter block
- } ToolFrontEndPanelStatus;
-
-
- /* prototypes of local functions */
- static void* InitDialog(PanelParameterBlock *pb);
- static void TermDialog(PanelParameterBlock *pb, void *storage);
- static OSErr OptionsToDialog(PanelParameterBlock *pb, Handle options, void *storage);
- static short DialogToOptions(PanelParameterBlock *pb, Handle options, void *storage);
- static short Filter(DialogPtr dp, EventRecord *event, short *itemHit, void *storage);
- static void ItemHit(PanelParameterBlock *pb, void *storage);
- static void Validate(Handle original, Handle current, Boolean *recompile, Boolean *relink, Boolean *reset);
- static short GetPref(AEKeyword keyword, AEDesc *prefsDesc, Handle settings);
- static short SetPref(AEKeyword keyword, const AEDesc *prefsDesc, Handle settings);
- static short GetFactory(Handle settings, DialogPtr dp);
- static short UpdatePref(Handle settings);
- static Boolean ComparePrefs(Handle prefsHand1, Handle prefsHand2);
- static pascal void PanelDrawIncludeBox(DialogPtr dp, short item);
- static pascal void PanelDrawOverallBox(DialogPtr dp, short item);
- static Boolean GetExtensionString(StringPtr extension);
- static void EnableMainItems(PanelParameterBlock *pb);
- static void DisableAllItems(PanelParameterBlock *pb);
- static void EnableIncludeItems(PanelParameterBlock *pb);
- static void DisableIncludeItems(PanelParameterBlock *pb);
- static OSErr DrawCustomItems(PanelParameterBlock *pb);
- static void DrawOverallBox(PanelParameterBlock *pb, ToolFrontEndPanelStatus** status);
- static void DrawIncludeBox(PanelParameterBlock *pb, ToolFrontEndPanelStatus** status);
- static void ImportSettings(PanelParameterBlock *pb, void *storage);
-
- static void *theStorage = NULL; // for DrawUserItem
-
-
- /*
- * main - entry-point for Drop-In Preferences Panel
- *
- */
-
- pascal short main(PanelParameterBlock *pb)
- {
- short err = noErr;
-
- EnterCodeResource();
- PrepareCallback();
-
- switch (pb->request)
- {
- case reqInitPanel:
- /* panel has just been loaded into memory */
- theStorage = NULL;
- break;
-
- case reqTermPanel:
- /* panel is about to be unloaded from memory */
- break;
-
- case reqInitDialog:
- /* hook our dialog item list into the preferences dialog */
- theStorage = pb->storage = InitDialog(pb);
- break;
-
- case reqTermDialog:
- /* unhook our dialog item list from the preferences dialog */
- TermDialog(pb, pb->storage);
- break;
-
- case reqPutData:
- /* put the data in the given handle into our dialog items */
- OptionsToDialog(pb, pb->currentPrefs, pb->storage);
- break;
-
- case reqGetData:
- /* fill in the given handle with our dialog items */
- err = DialogToOptions(pb, pb->currentPrefs, pb->storage);
- break;
-
- case reqFilter:
- /* filter an event in the dialog */
- err = Filter(pb->dialog, pb->event, &pb->itemHit, pb->storage);
- break;
-
- case reqItemHit:
- /* handle a hit on one of our dialog items */
- ItemHit(pb, pb->storage);
- break;
-
- case reqAEGetPref:
- /* return one item in the given handle as an Apple Event descriptor */
- err = GetPref(pb->prefsKeyword, &pb->prefsDesc, pb->currentPrefs);
- break;
-
- case reqAESetPref:
- /* change one item in the given handle according to the given Apple Event descriptor */
- err = SetPref(pb->prefsKeyword, &pb->prefsDesc, pb->currentPrefs);
- break;
-
- case reqValidate:
- /* determine if we need to reset paths, recompile, or relink */
- Validate(pb->originalPrefs, pb->currentPrefs, &pb->recompile, &pb->relink, &pb->reset);
- break;
-
- case reqGetFactory:
- /* return our factory settings */
- err = GetFactory(pb->factoryPrefs, pb->dialog);
- break;
-
- case reqUpdatePref:
- /* update the given handle to use the current format for our prefs data */
- err = UpdatePref(pb->currentPrefs);
- break;
-
- case reqDrawCustomItem:
- err = DrawCustomItems(pb);
- break;
-
- default:
- err = paramErr;
- break;
- }
-
- ExitCodeResource();
-
- return err;
- }
-
-
- /*
- * PanelDrawOverallBox - user item proc to draw box
- */
-
- static pascal void PanelDrawOverallBox(DialogPtr dp, short item)
- {
- #pragma unused (dp, item)
- ToolFrontEndPanelStatus** status;
-
- EnterCallback();
- status = (ToolFrontEndPanelStatus**)theStorage;
- if (status != NULL)
- DrawOverallBox((*status)->pb, status);
- ExitCallback();
- }
-
-
- static void DrawOverallBox(PanelParameterBlock *pb, ToolFrontEndPanelStatus** status)
- {
- Str63 s;
-
- GetIndString(s, 128, 3);
- CWPanlDrawPanelBox(pb, kOverallBoxItem, s);
-
- if ((*status)->current < 0)
- {
- // grey it out -- no extensions yet
- Pattern gray;
- Rect labelRect, itemRect;
- PenState savedPen;
-
- GetPenState(&savedPen);
- PenNormal();
-
- CWPanlGetItemRect(pb, kOverallBoxItem, &itemRect);
- CWPanlGetItemRect(pb, kCommandLabelItem, &labelRect);
-
- GetIndPattern(&gray, sysPatListID, 4);
- PenMode(patBic);
- PenPat(&gray);
- InsetRect(&itemRect, 1, 1);
- itemRect.top = labelRect.top - 1;
- PaintRect(&itemRect);
-
- SetPenState(&savedPen);
- }
- }
-
-
- /*
- * PanelDrawIncludeBox - user item proc to draw box
- */
-
- static pascal void PanelDrawIncludeBox(DialogPtr dp, short item)
- {
- #pragma unused (dp, item)
- ToolFrontEndPanelStatus** status;
-
- EnterCallback();
- status = (ToolFrontEndPanelStatus**)theStorage;
- if (status != NULL)
- DrawIncludeBox((*status)->pb, status);
- ExitCallback();
- }
-
-
- static void DrawIncludeBox(PanelParameterBlock *pb, ToolFrontEndPanelStatus** status)
- {
- Str63 s;
-
- GetIndString(s, 128, 4);
- CWPanlDrawPanelBox(pb, kIncludeBoxItem, s);
-
- if ((*status)->current >= 0 && !(*status)->enableIncludes)
- {
- // grey it out -- no include options
- Pattern gray;
- Rect itemRect;
- PenState savedPen;
-
- GetPenState(&savedPen);
- PenNormal();
- CWPanlGetItemRect(pb, kIncludeBoxItem, &itemRect);
- GetIndPattern(&gray, sysPatListID, 4);
- PenMode(patBic);
- PenPat(&gray);
- InsetRect(&itemRect, 1, 1);
- PaintRect(&itemRect);
- SetPenState(&savedPen);
- }
- }
-
-
- /*
- * InitDialog - initialize Dialog Box items for this panel
- *
- */
-
- static void *InitDialog(PanelParameterBlock *pb)
- {
- ToolFrontEndPanelStatus** status;
-
- DebugStr("\p InitDialog start");
-
- status = (ToolFrontEndPanelStatus**)NewHandleClear(sizeof(ToolFrontEndPanelStatus));
- (*status)->current = -1;
- (*status)->pb = pb;
-
- CWPanlAppendItems(pb, pb->version < DROPINPANELAPIVERSION_2 ? kItemListIDV1 : kItemListID);
-
- if (pb->version < DROPINPANELAPIVERSION_2)
- {
- // CW/7 API -- we have to install user item procs ourselves
- CWPanlInstallUserItem(pb, kIncludeBoxItem, PanelDrawIncludeBox);
- CWPanlInstallUserItem(pb, kOverallBoxItem, PanelDrawOverallBox);
- }
-
- // SelectDialogItemText(dp, baseItems + kCommandItem, 0, 32767);
- CWPanlActivateItem(pb, kCommandItem);
-
- return (void*)status;
- }
-
- /*
- * TermDialog - destroy Dialog Box items for this panel
- *
- */
-
- static void TermDialog(PanelParameterBlock *pb, void *storage)
- {
- if (storage != NULL)
- DisposeHandle((Handle)storage);
- if (pb->version < DROPINPANELAPIVERSION_2)
- {
- // CW/7 API -- we have to release the memory we allocated in InitDialog
- CWPanlRemoveUserItem(pb, kIncludeBoxItem);
- CWPanlRemoveUserItem(pb, kOverallBoxItem);
- }
- theStorage = NULL;
- }
-
-
- /*
- * DrawCustomItems - draw user items
- *
- */
-
- static OSErr DrawCustomItems(PanelParameterBlock *pb)
- {
- switch (pb->itemHit - pb->baseItems)
- {
- case kIncludeBoxItem:
- DrawIncludeBox(pb, (ToolFrontEndPanelStatus**)pb->storage);
- break;
- case kOverallBoxItem:
- DrawOverallBox(pb, (ToolFrontEndPanelStatus**)pb->storage);
- break;
- }
- return noErr;
- }
-
-
- /*
- * OptionsToDialog - copy the options data from the handle to the screen
- *
- */
-
- static OSErr OptionsToDialog(PanelParameterBlock *pb, Handle options, void *storage)
- {
- ToolFrontEndPanelStatus** status = (ToolFrontEndPanelStatus**)storage;
- ToolFrontEndPrefHandle prefsData = (ToolFrontEndPrefHandle) options;
- Byte state;
- int i;
- MenuHandle menu;
- ControlHandle popup;
- Handle controlData;
- PopupPrivateDataHandle popupData;
- OSErr err;
-
- DebugStr("\p OptionsToDialog start");
-
- // initialize the popup menus
- if (!(*status)->popupsInitialized)
- {
- // initialize the filename extensions popup
- CWPanlGetItemControl(pb, kExtensionPopupItem, &popup);
- controlData = (*popup)->contrlData;
- popupData = (PopupPrivateDataHandle)controlData;
- menu = (*popupData)->mHandle;
- DisableItem(menu, 2); // disable remove
- while (CountMItems(menu) > 2) DeleteMenuItem(menu, 3);
- SetControlMaximum(popup, 2);
- (*status)->current = -1;
-
- for (i = 0; i < (*prefsData)->numExtensions; i++)
- {
- if (i == 0)
- {
- AppendMenu(menu, "\p(-"); // separator line
- EnableItem(menu, 2); // enable remove
- (*status)->current = 0;
- SetControlMaximum(popup, 3);
- }
-
- state = HGetState(options);
- HLock(options);
- AppendMenu(menu, "\pgrog");
- SetMenuItemText(menu, CountMItems(menu), (*prefsData)->extensions[i].extension);
- SetControlMaximum(popup, GetControlMaximum(popup) + 1);
- HSetState(options, state);
-
- if (i == 0)
- SetControlValue(popup, 4); // select first extension
- }
-
- // initialize the include file scanner popup
- CWPanlGetItemControl(pb, kIncludeScannerItem, &popup);
- controlData = (*popup)->contrlData;
- popupData = (PopupPrivateDataHandle)controlData;
- menu = (*popupData)->mHandle;
-
- // find the include file scanner folder
- {
- Str31 folderName;
- FCBPBRec pb;
- CInfoPBRec ci;
- FSSpec *scanners;
- short actualCount;
- short index;
-
- pb.ioFCBIndx = 0; // use ioRefNum
- pb.ioRefNum = LMGetCurApRefNum();
- pb.ioNamePtr = NULL;
- err = PBGetFCBInfoSync(&pb);
- if (err != noErr) return err;
- GetIndString(folderName, 128, 1); // CodeWarrior Plugins
- ci.dirInfo.ioNamePtr = folderName;
- ci.dirInfo.ioVRefNum = pb.ioFCBVRefNum;
- ci.dirInfo.ioDrDirID = pb.ioFCBParID;
- ci.dirInfo.ioFDirIndex = 0;
- err = PBGetCatInfoSync(&ci);
- if (err != noErr) return err;
- GetIndString(folderName, 128, 2); // Include Scanners
-
- // iterate over all files in folder, adding to popup menu
- scanners = (FSSpec*)NewPtr(sizeof(FSSpec[100]));
- if (scanners == NULL) return MemError();
- index = 1;
- do
- {
- short i;
- err = GetDirItems(pb.ioFCBVRefNum, ci.dirInfo.ioDrDirID, folderName, true, false, scanners, 100, &actualCount, &index);
- for (i = 0; i < actualCount; i++)
- {
- AppendMenu(menu, "\pgrog");
- SetMenuItemText(menu, CountMItems(menu), scanners[i].name);
- SetControlMaximum(popup, GetControlMaximum(popup) + 1);
- }
- } while (err == noErr);
- DisposePtr((Ptr)scanners);
- }
-
- (*status)->popupsInitialized = true;
- }
-
- state = HGetState((Handle)status);
- HLock((Handle)status);
-
- CWPanlSetItemText(pb, kScriptIncludeFileItem, (*prefsData)->scriptIncludeFile);
-
- if ((*status)->current < 0)
- {
- // no current extension -- disable all items
- DisableAllItems(pb);
- (*status)->enableIncludes = false;
- }
- else
- {
- EnableMainItems(pb);
- (*status)->enableIncludes = ((*prefsData)->extensions[(*status)->current].extension[0] != 0);
- if ((*status)->enableIncludes)
- EnableIncludeItems(pb);
- else
- DisableIncludeItems(pb);
-
- // set up scanner popup menu selection
- {
- Str31 theScanner;
- short i, lim;
-
- CWPanlGetItemControl(pb, kIncludeScannerItem, &popup);
- controlData = (*popup)->contrlData;
- popupData = (PopupPrivateDataHandle)controlData;
- menu = (*popupData)->mHandle;
- BlockMoveData((*prefsData)->extensions[(*status)->current].scanner, theScanner,
- (*prefsData)->extensions[(*status)->current].scanner[0] + 1);
- for (i = 3, lim = CountMItems(menu); i <= lim; i++)
- {
- // if this is the scanner, then select it
- Str31 thisScanner;
- GetMenuItemText(menu, i, thisScanner);
- if (EqualString(thisScanner, theScanner, false, true))
- {
- SetControlValue(popup, i);
- break;
- }
- }
- }
-
- CWPanlSetItemText(pb, kIncludePathItem,
- (*prefsData)->extensions[(*status)->current].includeFileArg);
- CWPanlSetItemText(pb, kCommandItem,
- (*prefsData)->extensions[(*status)->current].commandTemplate);
- }
-
- HSetState((Handle)status, state);
- DebugStr("\p OptionsToDialog end");
- return noErr;
- }
-
-
- /*
- * DialogToOptions - copy the options data from screen to the handle
- *
- */
-
- static short DialogToOptions(PanelParameterBlock *pb, Handle options, void *storage)
- {
- ToolFrontEndPanelStatus** status = (ToolFrontEndPanelStatus**)storage;
- ToolFrontEndPref ** prefsData = (ToolFrontEndPrefHandle) options;
- Str255 tempStr;
- Byte state;
- MenuHandle menu;
- ControlHandle popup;
- Handle controlData;
- PopupPrivateDataHandle popupData;
-
- DebugStr("\p DialogToOptions start");
-
- state = HGetState((Handle)status);
- HLock((Handle)status);
-
- CWPanlGetItemText(pb, kScriptIncludeFileItem, tempStr, 255);
- if (StrLength(tempStr) >= sizeof((*prefsData)->scriptIncludeFile))
- tempStr[0] = sizeof((*prefsData)->scriptIncludeFile) - 1;
- BlockMoveData(tempStr, (*prefsData)->scriptIncludeFile, StrLength(tempStr)+1);
-
- if ((*status)->current < 0)
- {
- // no current extension
- }
- else
- {
- // extract data from scanner popup menu
- CWPanlGetItemControl(pb, kIncludeScannerItem, &popup);
- controlData = (*popup)->contrlData;
- popupData = (PopupPrivateDataHandle)controlData;
- menu = (*popupData)->mHandle;
- if (GetControlValue(popup) == 1)
- {
- (*prefsData)->extensions[(*status)->current].scanner[0] = 0;
- }
- else if (menu != NULL) // somehow this goes NULL when you switch to another panel ? ! ?
- {
- Str31 scanner;
- GetMenuItemText(menu, GetControlValue(popup), scanner);
- BlockMoveData(scanner, (*prefsData)->extensions[(*status)->current].scanner, StrLength(scanner)+1);
- }
-
- CWPanlGetItemText(pb, kIncludePathItem, tempStr, 255);
- if (StrLength(tempStr) >= sizeof((*prefsData)->extensions[(*status)->current].includeFileArg))
- tempStr[0] = sizeof((*prefsData)->extensions[(*status)->current].includeFileArg) - 1;
- BlockMoveData(tempStr, (*prefsData)->extensions[(*status)->current].includeFileArg, StrLength(tempStr)+1);
-
- CWPanlGetItemText(pb, kCommandItem, tempStr, 255);
- if (StrLength(tempStr) >= sizeof((*prefsData)->extensions[(*status)->current].commandTemplate))
- tempStr[0] = sizeof((*prefsData)->extensions[(*status)->current].commandTemplate) - 1;
- BlockMoveData(tempStr, (*prefsData)->extensions[(*status)->current].commandTemplate, StrLength(tempStr)+1);
- }
-
- HSetState((Handle)status, state);
-
- DebugStr("\p DialogToOptions end");
- return noErr;
- }
-
- /*
- * Filter - filter an event for the Preferences panel
- *
- */
-
- static short Filter(DialogPtr dp, EventRecord *event, short *itemHit, void *storage)
- {
- #pragma unused(dp, event, itemHit, storage)
- return noErr;
- }
-
-
- /*
- * ItemHit - handle an itemHit in a Preferences panel
- *
- */
-
- static void ItemHit(PanelParameterBlock *pb, void *storage)
- {
- short theItem = pb->itemHit - pb->baseItems;
- ToolFrontEndPanelStatus** status = (ToolFrontEndPanelStatus**)storage;
- ToolFrontEndPref** current = (ToolFrontEndPrefHandle) pb->currentPrefs;
- ToolFrontEndPref** original = (ToolFrontEndPrefHandle) pb->originalPrefs;
- ControlHandle ctrlHand;
- short value;
-
- DebugStr("\p ItemHit start -- item number:");
- {
- Str31 s;
- NumToString(theItem, s);
- DebugStr(s);
- }
-
- switch (theItem)
- {
- case kExtensionPopupItem:
- CWPanlGetItemControl(pb, theItem, &ctrlHand);
- value = GetControlValue(ctrlHand);
- switch (value)
- {
- case 1:
- // add new extension
- {
- Str15 extension;
- Byte state;
- Size size;
-
- // get the menu
- Handle controlData = (*ctrlHand)->contrlData;
- PopupPrivateDataHandle popupData = (PopupPrivateDataHandle)controlData;
- MenuHandle menu = (*popupData)->mHandle;
-
- // put up a dialog asking for an extension string
- if (!GetExtensionString(extension)) break;
-
- // XXX search the existing prefs for the string -- no dupes!
-
- // add a new entry at the end of the prefs
- state = HGetState((Handle)current);
- HLock((Handle)current);
- size = GetHandleSize((Handle)current);
- if (state & 0x4)
- SetResourceSize((Handle)current, size + sizeof(struct ExtensionEntry[1]));
- else
- SetHandleSize((Handle)current, size + sizeof(struct ExtensionEntry[1]));
- BlockMoveData(extension,
- (*current)->extensions[(*current)->numExtensions].extension,
- extension[0] + 1);
- (*current)->extensions[(*current)->numExtensions].includeFileArg[0] = 0;
- (*current)->extensions[(*current)->numExtensions].scanner[0] = 0;
- (*current)->extensions[(*current)->numExtensions].commandTemplate[0] = 0;
- (*current)->numExtensions++;
- HSetState((Handle)current, state);
-
- // add a new item at the end of the menu
- if ((*current)->numExtensions == 1)
- AppendMenu(menu, "\p(-");
- AppendMenu(menu, extension);
-
- // set the menu item and current status item
- (*status)->current = (*current)->numExtensions - 1;
- SetControlMaximum(ctrlHand, (*current)->numExtensions + 3);
- SetControlValue(ctrlHand, (*current)->numExtensions + 3);
-
- // redraw the dialog
- EnableMainItems(pb);
- DisableIncludeItems(pb);
- (*status)->enableIncludes = false;
- CWPanlInvalItem(pb, kOverallBoxItem);
- OptionsToDialog(pb, pb->currentPrefs, storage);
- }
- break;
-
- case 2:
- // remove current extension
- {
- Byte state;
- Size size;
-
- // get the menu
- Handle controlData = (*ctrlHand)->contrlData;
- PopupPrivateDataHandle popupData = (PopupPrivateDataHandle)controlData;
- MenuHandle menu = (*popupData)->mHandle;
-
- // delete the menu item
- DeleteMenuItem(menu, value);
-
- // shift and resize data in the handle
- --(*current)->numExtensions;
- if ((*current)->numExtensions != (*status)->current)
- {
- // shift back later entries
- BlockMoveData((*current)->extensions + (*status)->current + 1,
- (*current)->extensions + (*status)->current,
- sizeof(struct ExtensionEntry[1])
- * ((*current)->numExtensions - (*status)->current));
- }
- state = HGetState((Handle)current);
- size = GetHandleSize((Handle)current);
- if (state & 0x4)
- SetResourceSize((Handle)current, size - sizeof(struct ExtensionEntry[1]));
- else
- SetHandleSize((Handle)current, size - sizeof(struct ExtensionEntry[1]));
-
- // set the menu item and current status item
- if ((*current)->numExtensions == 0)
- {
- // last one went away
- DeleteMenuItem(menu, 3); // delete separator
- DisableItem(menu, 2); // delete remove item
- SetControlValue(ctrlHand, 1);
- (*status)->current = -1;
-
- // redraw the dialog
- DisableAllItems(pb);
- CWPanlInvalItem(pb, kOverallBoxItem);
- }
- else
- {
- (*status)->current = 0; // select first item
- SetControlValue(ctrlHand, 4);
-
- // redraw the dialog
- (*status)->enableIncludes = ((*current)->extensions[(*status)->current].scanner[0] != 0);
- if ((*status)->enableIncludes)
- EnableIncludeItems(pb);
- else
- DisableIncludeItems(pb);
- CWPanlInvalItem(pb, kOverallBoxItem);
- }
-
- OptionsToDialog(pb, pb->currentPrefs, storage);
- }
- break;
-
- default:
- // select current extension
- DialogToOptions(pb, pb->currentPrefs, storage);
- (*status)->current = value - 4;
-
- // redraw the dialog
- (*status)->enableIncludes = ((*current)->extensions[(*status)->current].scanner[0] != 0);
- if ((*status)->enableIncludes)
- EnableIncludeItems(pb);
- else
- DisableIncludeItems(pb);
- CWPanlInvalItem(pb, kOverallBoxItem);
- OptionsToDialog(pb, pb->currentPrefs, storage);
- break;
- }
- break;
-
- case kImportSettingsItem:
- // import settings from another project file
- ImportSettings(pb, storage);
- break;
-
- default:
- DialogToOptions(pb, pb->currentPrefs, storage);
- break;
- }
-
- pb->canRevert = !ComparePrefs(pb->originalPrefs, pb->currentPrefs);
- pb->canFactory = !ComparePrefs(pb->factoryPrefs, pb->currentPrefs);
-
- DebugStr("\p ItemHit end");
- }
-
-
- // file filter to excelude open files
-
- static pascal Boolean NonOpenFileFilter(CInfoPBPtr info)
- {
- return (info->hFileInfo.ioFlAttrib & 0x80) == 0 ? false : true;
- }
-
-
- /*
- * ImportSettings - import settings from another project file
- *
- */
-
- static void ImportSettings(PanelParameterBlock *pb, void *storage)
- {
- ToolFrontEndPanelStatus** status = (ToolFrontEndPanelStatus**)storage;
- Handle current = (Handle) pb->currentPrefs;
- OSType types = 'MMPR';
- StandardFileReply reply;
- short resRefNum;
- Handle h;
- long size;
- Byte state;
-
- // select a project file which is not open (that is, not this one....)
- StandardGetFile(NonOpenFileFilter, 1, &types, &reply);
- if (!reply.sfGood) return;
-
- // open the resource file, fetch the resource and close the file
- resRefNum = FSpOpenResFile(&reply.sfFile, fsRdPerm);
- if (resRefNum < 0)
- {
- SysBeep(6);
- return;
- }
- h = Get1NamedResource('pref', "\pToolFrontEnd Panel");
- if (h == NULL)
- {
- CloseResFile(resRefNum);
- SysBeep(6);
- return;
- }
- DetachResource(h);
- CloseResFile(resRefNum);
-
- // set the current preferences to match the resource
- size = GetHandleSize(h);
- state = HGetState(current);
- if (state & 0x4)
- SetResourceSize(current, size);
- else
- SetHandleSize(current, size);
- BlockMoveData(*h, *current, size);
- if (state & 0x4)
- ChangedResource(current);
- DisposeHandle(h);
-
- // update the dialog
- (*status)->popupsInitialized = false;
- CWPanlInvalItem(pb, kOverallBoxItem);
- OptionsToDialog(pb, current, storage);
- }
-
-
- /*
- * Validate - check if panel's changes require a recompile or relink
- *
- */
-
- static void Validate(Handle original, Handle current, Boolean *recompile, Boolean *relink, Boolean *reset)
- {
- #pragma unused(original, current)
-
- // XXX Validate
- *recompile = false;
- *relink = false;
- *reset = false;
- }
-
- /*
- * GetPref - get a specified Preference setting for an AppleEvent request
- *
- */
-
- static short GetPref(AEKeyword keyword, AEDesc *prefsDesc, Handle settings)
- {
- ToolFrontEndPref prefsData = ** (ToolFrontEndPrefHandle) settings;
- DescType anEnum;
- OSErr err;
-
- switch (keyword)
- {
- #if 0
- // XXX get a specified Preference setting for an AppleEvent request
- case prefsTFE_IncludeFile:
- err = AECreateDesc(typeText, (*prefsData)->extensions[(*status)->current].scriptIncludeFile + 1,
- (*prefsData)->extensions[(*status)->current].scriptIncludeFile[0], prefsDesc);
- break;
-
- case prefsPR_ProjectType:
- switch ((*prefsData)->extensions[(*status)->current].projtype)
- {
- case kProjTypeApplication: anEnum = enum_Project_Application; break;
- case kProjTypeLibrary: anEnum = enum_Project_Library; break;
- case kProjTypeSharedLib: anEnum = enum_Project_SharedLibrary; break;
- case kProjTypeCodeResource: anEnum = enum_Project_CodeResource; break;
- case kProjTypeMPWTool: anEnum = enum_Project_MPWTool; break;
- default: return (paramErr);
- }
- err = AECreateDesc(typeEnumeration, &anEnum, sizeof(anEnum), prefsDesc);
- break;
-
- case prefsPR_FileName:
- err = AECreateDesc(typeChar, (*prefsData)->extensions[(*status)->current].outfile+1, StrLength((*prefsData)->extensions[(*status)->current].outfile), prefsDesc);
- break;
- #endif
-
- default:
- err = errAECantHandleClass;
- break;
- }
-
- return (err);
- }
-
- /*
- * SetPref - set a specified Preference setting from an AppleEvent request
- *
- */
-
- static short SetPref(AEKeyword keyword, const AEDesc *prefsDesc, Handle settings)
- {
- ToolFrontEndPref prefsData = ** (ToolFrontEndPrefHandle) settings;
- AEDesc toDesc = { typeNull, NULL };
- OSErr err = noErr;
- Handle dataHand;
- Size textLength;
- DescType anEnum;
-
- switch (keyword)
- {
- #if 0
- // XXX set a specified Preference setting from an AppleEvent request
- case prefsLN_GenerateSymFile:
- if (prefsDesc->descriptorType == typeBoolean)
- {
- dataHand = prefsDesc->dataHandle;
- }
- else
- {
- err = AECoerceDesc(prefsDesc, typeBoolean, &toDesc);
- if (err == noErr)
- dataHand = toDesc.dataHandle;
- }
- if (err == noErr)
- {
- (*prefsData)->extensions[(*status)->current].linksym = ** (Boolean **) dataHand;
- }
- break;
-
- case prefsPR_ProjectType:
- if (prefsDesc->descriptorType != typeEnumeration)
- {
- err = errAETypeError;
- break;
- }
-
- anEnum = ** (DescType **) prefsDesc->dataHandle;
-
- switch (anEnum)
- {
- case enum_Project_Application: (*prefsData)->extensions[(*status)->current].projtype = kProjTypeApplication; break;
- case enum_Project_Library: (*prefsData)->extensions[(*status)->current].projtype = kProjTypeLibrary; break;
- case enum_Project_SharedLibrary: (*prefsData)->extensions[(*status)->current].projtype = kProjTypeSharedLib; break;
- case enum_Project_CodeResource: (*prefsData)->extensions[(*status)->current].projtype = kProjTypeCodeResource; break;
- case enum_Project_MPWTool: (*prefsData)->extensions[(*status)->current].projtype = kProjTypeMPWTool; break;
- default: return (errAECoercionFail);
- }
- break;
-
- case prefsPR_FileName:
- if (prefsDesc->descriptorType == typeChar)
- {
- dataHand = prefsDesc->dataHandle;
- }
- else
- {
- err = AECoerceDesc(prefsDesc, typeChar, &toDesc);
- if (err == noErr)
- dataHand = toDesc.dataHandle;
- }
- if (err == noErr)
- {
- textLength = GetHandleSize(dataHand);
- if (textLength > sizeof((*prefsData)->extensions[(*status)->current].outfile) - 1)
- textLength = sizeof((*prefsData)->extensions[(*status)->current].outfile) - 1;
- BlockMoveData(*dataHand, (*prefsData)->extensions[(*status)->current].outfile+1, textLength);
- (*prefsData)->extensions[(*status)->current].outfile[0] = textLength;
- }
- break;
- #endif
-
- default:
- err = errAECantHandleClass;
- break;
- }
-
- if (err == noErr)
- {
- ** (ToolFrontEndPrefHandle) settings = prefsData;
- }
-
- AEDisposeDesc(&toDesc);
-
- return (err);
- }
-
- /*
- * GetFactory - retrieve factory settings
- *
- */
-
- static short GetFactory(Handle settings, DialogPtr dp)
- {
- #pragma unused(dp)
-
- OSErr err;
- SetHandleSize(settings, sizeof(ToolFrontEndPref));
- err = MemError();
- if (err == noErr)
- {
- int i;
- char *c;
-
- for (i = sizeof(ToolFrontEndPref), c = (char*)*settings; i > 0; i--)
- *c++ = 0;
- (*(ToolFrontEndPref**)settings)->version = PTOOLFRONTENDVERSION;
- }
- return (err);
- }
-
- /*
- * UpdatePref - "upgrade" a pref to the current version
- *
- */
-
- static short UpdatePref(Handle settings)
- {
- ToolFrontEndPrefHandle prefsHand = (ToolFrontEndPrefHandle) settings;
- OSErr err = noErr;
-
- switch ((*prefsHand)->version)
- {
- case PTOOLFRONTENDVERSION:
- break;
- default:
- err = kBadPrefVersion;
- break;
- }
-
- return (err);
- }
-
-
- static Boolean ComparePrefs(Handle prefsHand1, Handle prefsHand2)
- {
- ToolFrontEndPrefHandle prefs1 = (ToolFrontEndPrefHandle) prefsHand1;
- ToolFrontEndPrefHandle prefs2 = (ToolFrontEndPrefHandle) prefsHand2;
- Boolean differ = false;
- Byte state1, state2;
-
- state1 = HGetState(prefsHand1);
- HLock(prefsHand1);
- state2 = HGetState(prefsHand2);
- HLock(prefsHand2);
-
- if ((*prefs1)->numExtensions != (*prefs2)->numExtensions)
- {
- differ = true;
- }
- else
- {
- int i;
- differ = EqualString((*prefs1)->scriptIncludeFile, (*prefs2)->scriptIncludeFile, false, true);
- for (i = 0; !differ && i < (*prefs1)->numExtensions; i++)
- {
- differ = ( EqualString((*prefs1)->extensions[i].extension, (*prefs2)->extensions[i].extension, false, true)
- && EqualString((*prefs1)->extensions[i].scanner, (*prefs2)->extensions[i].scanner, false, true)
- && EqualString((*prefs1)->extensions[i].includeFileArg, (*prefs2)->extensions[i].includeFileArg, false, true)
- && EqualString((*prefs1)->extensions[i].commandTemplate, (*prefs2)->extensions[i].commandTemplate, false, true));
- }
- }
-
- HSetState(prefsHand1, state1);
- HSetState(prefsHand2, state2);
-
- return !differ;
- }
-
-
- void EnableMainItems(PanelParameterBlock *pb)
- {
- DebugStr("\p EnableMainItems start");
- CWPanlEnableItem(pb, kIncludeScannerItem, true);
- CWPanlEnableItem(pb, kCommandItem, true);
- DebugStr("\p EnableMainItems end");
- }
-
-
- void EnableIncludeItems(PanelParameterBlock *pb)
- {
- DebugStr("\p EnableIncludeItems start");
- CWPanlEnableItem(pb, kIncludeScannerItem, true);
- CWPanlEnableItem(pb, kCommandItem, true);
- DebugStr("\p EnableIncludeItems end");
- }
-
-
- void DisableAllItems(PanelParameterBlock *pb)
- {
- DebugStr("\p DisableAllItems start");
- CWPanlEnableItem(pb, kCommandItem, false);
- DisableIncludeItems(pb);
- DebugStr("\p DisableAllItems end");
- }
-
-
- void DisableIncludeItems(PanelParameterBlock *pb)
- {
- DebugStr("\p DisableIncludeItems start");
- CWPanlEnableItem(pb, kIncludeScannerItem, false);
- CWPanlEnableItem(pb, kIncludePathItem, false);
- DebugStr("\p DisableIncludeItems end");
- }
-
-
- Boolean GetExtensionString(StringPtr extension)
- {
- short itemHit;
- short itemType;
- Rect itemRect;
- Handle itemHand;
- Boolean done, result;
-
- DialogPtr dialog = GetNewDialog(kGetExtensionDialog, NULL, (WindowPtr)-1);
- SelectDialogItemText(dialog, kExtensionTextItem, 0, 32767);
- done = false;
- do
- {
- ModalDialog(NULL, &itemHit);
- switch (itemHit)
- {
- case ok:
- GetDialogItem(dialog, kExtensionTextItem, &itemType, &itemHand, &itemRect);
- GetDialogItemText(itemHand, extension);
- result = true;
- done = true;
- break;
- case cancel:
- result = false;
- done = true;
- break;
- }
- } while (!done);
- DisposeDialog(dialog);
-
- return result;
- }
-